<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>重置密码</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            margin: 0;
            padding: 20px;
            color: #333;
            background-color: #f8f9fa;
        }
        .container {
            max-width: 800px;
            margin: 40px auto;
            background-color: #fff;
            padding: 30px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        h1 {
            color: #007bff;
            text-align: center;
            margin-bottom: 30px;
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        .btn {
            display: inline-block;
            background-color: #007bff;
            color: #fff;
            padding: 10px 20px;
            text-decoration: none;
            border-radius: 5px;
            border: none;
            cursor: pointer;
            font-size: 16px;
            margin: 10px;
        }
        .btn:hover {
            background-color: #0069d9;
        }
        #result {
            margin-top: 20px;
            padding: 15px;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: #f5f5f5;
            min-height: 100px;
            white-space: pre-wrap;
            font-family: monospace;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>重置密码</h1>
        
        <div class="form-group">
            <label for="identifier">用户名或邮箱</label>
            <input type="text" id="identifier" name="identifier">
        </div>
        
        <div class="form-group">
            <label for="newPassword">新密码</label>
            <input type="password" id="newPassword" name="newPassword">
        </div>
        
        <div>
            <button id="resetPassword" class="btn">重置密码</button>
            <button id="viewUsers" class="btn">查看所有用户</button>
        </div>
        
        <div id="result">
            <p>结果将显示在这里...</p>
        </div>
    </div>

    <script>
        document.getElementById('resetPassword').addEventListener('click', function() {
            const resultDiv = document.getElementById('result');
            const identifier = document.getElementById('identifier').value;
            const newPassword = document.getElementById('newPassword').value;
            
            resultDiv.innerHTML = `<p>重置密码...</p>`;
            resultDiv.innerHTML += `<p>用户名/邮箱: ${identifier}</p>`;
            
            // 创建表单数据
            const formData = new URLSearchParams();
            formData.append('identifier', identifier);
            formData.append('newPassword', newPassword);
            
            // 发送请求
            fetch('/file-transfer/debug/reset-password', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                body: formData
            })
            .then(response => {
                resultDiv.innerHTML += `<p>响应状态: ${response.status}</p>`;
                return response.text();
            })
            .then(text => {
                resultDiv.innerHTML += `<p>响应数据: ${text}</p>`;
                try {
                    const data = JSON.parse(text);
                    if (data.success) {
                        resultDiv.innerHTML += `<p>密码重置成功!</p>`;
                    } else {
                        resultDiv.innerHTML += `<p>密码重置失败: ${data.message}</p>`;
                    }
                } catch (e) {
                    resultDiv.innerHTML += `<p>解析JSON失败: ${e.message}</p>`;
                }
            })
            .catch(error => {
                resultDiv.innerHTML += `<p>错误: ${error.message}</p>`;
            });
        });
        
        document.getElementById('viewUsers').addEventListener('click', function() {
            const resultDiv = document.getElementById('result');
            resultDiv.innerHTML = `<p>获取所有用户...</p>`;
            
            fetch('/file-transfer/debug/users')
                .then(response => {
                    resultDiv.innerHTML += `<p>响应状态: ${response.status}</p>`;
                    return response.text();
                })
                .then(text => {
                    resultDiv.innerHTML += `<p>用户列表:</p>`;
                    try {
                        const users = JSON.parse(text);
                        users.forEach(user => {
                            resultDiv.innerHTML += `<p>ID: ${user.id}, 用户名: ${user.username}, 邮箱: ${user.email}</p>`;
                        });
                    } catch (e) {
                        resultDiv.innerHTML += `<p>解析JSON失败: ${e.message}</p>`;
                        resultDiv.innerHTML += `<p>原始响应: ${text}</p>`;
                    }
                })
                .catch(error => {
                    resultDiv.innerHTML += `<p>错误: ${error.message}</p>`;
                });
        });
    </script>
</body>
</html> 